package com.gx.controller;

import com.gx.domain.ScheduleJob;
import com.gx.page.TableDataInfo;
import com.gx.response.R;
import com.gx.service.api.ScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/jobs")
public class JobController extends BaseController {

    @Autowired
    private ScheduleJobService scheduleJobService;

    @GetMapping
    public R list() {
        startPage();
        List<ScheduleJob> scheduleJobs = scheduleJobService.queryList(null);
        TableDataInfo dataTable = getDataTable(scheduleJobs);
        return R.ok().put("rows", dataTable.getRows()).put("total", dataTable.getTotal());
    }

    @PostMapping
    public R sava(@RequestBody ScheduleJob scheduleJob) {
        scheduleJobService.save(scheduleJob);
        return R.ok("新增成功");
    }
}
